<!-- 备案项目查询 -->
<template>
  <div class="home-index-content">
    <Table :columns="columns" :data="busInfoForewarningVoList">
      <template slot-scope="{ row }" slot="projectName">
        <BtnText type="primary" @BtnClick="goToBusinessInfo(row)">{{ row.projectName }}</BtnText>
      </template>
      <template slot-scope="{ row }" slot="sendFlag">{{ row.sendFlag ? '已发送短信提醒':'未发送短信提醒' }}</template>
      <template slot-scope="{ row }" slot="action">
        <BtnText type="primary" @BtnClick="onView(row)">详情</BtnText>
        <BtnText type="warning" @BtnClick="onSend(row)">发送短信</BtnText>
      </template>
    </Table>
  </div>
</template>

<script>
import { sendForewarningSms } from '@/api/businessInformationManage.js'

export default {
  name: "expandTable",
  props: {
    busInfoForewarningVoList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      columns: [
        {
          title: "项目名称",
          key: "projectName",
          slot: 'projectName',
          minWidth: 240,
        },
        {
          title: "业主方",
          key: "ownerCompanyName",
          minWidth: 160,
        },
        {
          title: "施工方",
          key: "constructionName",
          minWidth: 160,
        },
        {
          title: "项目地址",
          key: "projectAddressName",
          minWidth: 240,
          tooltip: true
        },
        {
          title: "预计产值规模(万元)",
          key: "outputScale",
          minWidth: 160,
        },
        {
          title: "反馈阶段",
          key: "feedbackPhaseName",
          minWidth: 120,
        },
        {
          title: "信息分类",
          key: "forewarningInfoClassifyName",
          minWidth: 170,
        },
        {
          title: "预警信息",
          slot: "sendFlag",
          minWidth: 160,
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center',
          fixed: 'right'
        },
      ],
      listData: []
    };
  },
  methods: {
    goToBusinessInfo ({ busiInfoId }) {
      this.$router.push({ path: '/businessInformationDetails', query: { busiInfoId, type: 'view', page: 'businessInformationWarning' } })
    },
    onSend (row) {
      let { timeHour, mobile, name, busInfoForewarningId, smsCode } = row
      if (!mobile) {
        this.$Message.error('手机号为空, 无法发送短信!');
        return
      }
      if (!smsCode) {
        this.$Message.error('未配置短信模板, 无法发送短信!');
        return
      }
      timeHour = timeHour < 24 ? `${timeHour}小时` : timeHour / 24 + '天'
      this.$Modal.confirm({
        title: '发送短信',
        okText: '发送',
        width: 550,
        content: `<p>项目名称
          <span class="send-modal-red send-modal-strong">超过${timeHour}未反馈</span> ，
          将发送短信至<span class=" send-modal-strong"> ${name || ''} </span>手机
          <span class=" send-modal-strong">${mobile}</span>上！
          请及时登录到平台查看！
        </p>`,
        onOk: async () => {
          const request = {
            busInfoForewarningId,
            mobile,
            smsCode
          }
          const data = await sendForewarningSms(request)
          const tip = data ? '成功' : '失败'
          this.$Message.success(`短信发送${tip}！`);
        },
      });
    },
    onView ({ busInfoForewarningId, forewarningInfoClassify }) {
      const type = forewarningInfoClassify === 'NotReceiveForewarning' ? 'receive' : 'feedback'
      this.$router.push({ path: '/businessInfoWarningDetails', query: { busInfoForewarningId, type } });
    },

  },
};
</script>

<style lang="less" scoped></style>
